<?php

include ('../session.php');
include ('../db.php');
include ('../functions.php');
include ('config.php');

if ($action == 'add')
{
  print_r ($_POST);

  $c_name = mysql_clean ($name);
  $c_locationid = intval ($location);

  $query = "select event_id
            from " . DKP_EVENTS . "
            where event_name = '$c_name'
            and location_id = $c_locationid";
  $result = mysql_query ($query);

  $row = mysql_fetch_array ($result);

  if ($row)
  {
  }

  $query = "select idvalue
            from ids
            where idid = " . ID_EVENT;
  $result = mysql_query ($query);

  $row = mysql_fetch_array ($result);

  $eventid = $row['idvalue'];
  $c_eventid = intval ($eventid);

  $query = "insert into " . DKP_EVENTS . "
            (event_id, event_name, location_id)
            values ($c_eventid, '$c_name', $c_locationid)";
  $result = mysql_query ($query);

  $query = "update ids
            set idvalue = " . intval ($eventid + 1) . "
            where idid = " . ID_EVENT;
  $result = mysql_query ($query);
}
else if ($action == 'update')
{
}
else if ($action == 'remove')
{
}

$output = '';

$output .= "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
  <head>
    <title>Panic Points - Add Event</title>
    <link href=\"../general.css\" rel=\"stylesheet\" type=\"text/css\">
  </head>
  <body>";

include ('navigation.php');

$output .= "
    <form name=\"eventform\" id=\"eventform\" action=\"addevent.php\" method=\"POST\">
      <input type=\"hidden\" name=\"action\" id=\"action\" value=\"\">
      <table>
        <tr>
          <td>name</td>
          <td><input type=\"edit\" name=\"name\"></td>
        </tr>
        <tr>
          <td>location</td>
          <td>
            <select name=\"location\">";

$query = "select location_id, location_name
          from " . DKP_LOCATIONS . "
          order by location_name asc";
$result = mysql_query ($query);

while ($row = mysql_fetch_array ($result))
{
  $output .= "
              <option value=\"" . $row['location_id'] . "\">" . $row['location_name'] . "</option>";
}

$output .= "
            </select>
          </td>
        </tr>
        <tr>
          <td colspan=\"2\">
            <button onclick=\"document.getElementById ('action').value = 'add'; document.getElementById ('eventform').submit ()\">add</button>&nbsp;
            <button onclick=\"document.getElementById ('action').value = 'update'; document.getElementById ('eventform').submit ()\">update</button>&nbsp;
            <button onclick=\"document.getElementById ('action').value = 'remove'; document.getElementById ('eventform').submit ()\">remove</button>
          </td>
        </tr>
      </table>
    </form>";

$output .= "
  </body>
</html>";

echo $output;
